<template>
  <div>
    <div class="header">
      <img src="../../../public/image/3.png" alt="" />
    </div>
    <div class="title">
      <span>扶农政策</span>
      <span class="postion">您现在的位置：扶农政策</span>
    </div>
    <div class="type">
      <div class="active">全部</div>
      <div>扶贫助农政策1</div>
      <div>扶贫助农政策2</div>
      <div>扶贫助农政策3</div>
      <div>扶贫助农政策4</div>
      <div>扶贫助农政策5</div>
      <div>扶贫助农政策6</div>
    </div>
    <div class="search">
      <div>
        <!-- 这个div是为了控制搜索框在右边 -->
      </div>
      <div>
        标题
        <input type="text" placeholder="标题" />
        <el-button
          slot="append"
          icon="el-icon-search"
          type="primary"
          size="mini"
          >搜索</el-button
        >
      </div>
    </div>
    <ul class="mod-item">
      <li
        v-for="(item, index) in list_fupin"
        :key="index"
        @click="$router.push('/fupinview/fupininfo/' + item.id)"
      >
        <img :src="item.cover" alt="" />
        <span>{{ item.title }}</span>
      </li>
    </ul>
    <div style="margin: 20px auto">
      <el-pagination
        style="text-align: center"
        layout="prev, pager, next,jumper"
        :total="total"
        :page-size="pageSize"
        background
        @current-change="current"
      >
      </el-pagination>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      list_fupin: [],
      pageNum: 1,
      pageSize: 4,
      total: 0,
    };
  },
  methods: {
    async getFuPin(pageNum, pageSize) {
      let { data: res } = await this.$axios.get("/alleviation/getlist", {
        params: {
          pageNum,
          pageSize,
        },
      });
      // window.console.log(res);
      this.total = res.data.total;
      this.list_fupin = res.data.list;
    },
    current(e) {
      // window.console.log(e);
      this.pageNum = e;
      this.getFuPin(this.pageNum, this.pageSize);
    },
    addActive() {
      let types=[...document.querySelectorAll('.type>div')];
    //   window.console.log(types);
      for (const type of types) {
          //给每一个type绑定点击事件
          type.addEventListener('click',function(){
             //去掉其他节点active，给当前节点添加active类
             for (let i = 0; i < types.length; i++) {
                types[i].classList.remove('active');
             }
             this.classList.add('active');
             window.console.log(this.innerText)
          })
      }
    },
  },
  created() {
    this.getFuPin(this.pageNum, this.pageSize);
   
  },
  mounted(){
   this.addActive();
  }
};
</script>
<style lang="scss" scoped>
.header {
  width: 100%;
  img {
    height: 400px;
    width: 100%;
  }
}
.title {
  width: 80%;
  margin: 10px auto;
  padding-left: 5px;
  height: 40px;
  line-height: 40px;
  border-left: 8px #666 solid;
  span {
    font-size: 15px;
    color: #000;
  }
  .postion {
    font-size: 12px;
    color: #666;
    margin-left: 30px;
  }
}
.type {
  width: 80%;
  margin: 10px auto;
  display: flex;
  color: white;
  :first-child {
    margin-right: 2px;
  }
  .active {
    background-color: rgb(83, 208, 246);
  }
  div{
    font-size: 12px;
    width: 90px;
    height: 30px;
    line-height: 30px;
    text-align: center;
    background-color: #333;
  }
}

.search {
  width: 80%;
  height: 40px;
  margin: 10px auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  input {
    text-align: center;
    height: 40px;
    width: 100px;
    border: none;
    border-bottom: 1px solid #000;
    outline: none;
  }
}
.mod-item {
  width: 80%;
  //   border: 1px solid salmon;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  li {
    width: 48%;
    height: 130px;
    border: 1px #d3d7d4 solid;
    border-radius: 5px;
    box-shadow: 0 0 3px #d3d7d4;
    margin: 5px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    img {
      width: 130px;
      height: 130px;
    }
    span {
      display: inline-block;
      margin-right: 10px;
      position: relative;
      top: -50px;
      color: skyblue;
      font-size: 20px;
    }
  }
}
</style>